<html>
    <head>
        <meta charset="utf-8">
        <title>地图事件:Click</title>
        <!-- leaflet的css样式 -->
        <link rel="stylesheet" href="../lib/leaflet.css" />
        <!-- leaflet的js库 -->
        <script type="text/javascript" src="../lib/leaflet-src.js"></script>
        <!-- 地图容器样式 -->
        <style>
            #mapDiv{
                width: 100%;
                height: 100%;
            }
        </style>

        <script type="text/javascript">
            var map = null; 

            function init(){

                map = L.map("mapDiv", { 
                    layers: [
                        L.tileLayer( 'http://{s}.tile.osm.org/{z}/{x}/{y}.png')
                    ]
                    center: [39,116],
                    zoom: 9
                });

                // function(ev)即匿名函数，无需定义函数名
                map.on('click', function(ev) {
                    document.getElementById("XY").value = ev.latlng;
                });

                //1. 绑定map的click事件
                map.on('ckick', onClick);
                //2. 定义click事件的响应函数
                function onClick(ev){

                }

            }

            
            function onGetCenterAndZoom()
            {
                //map.center = [116,39];
                //map.setView([116,39],3);
                var center = map.getCenter();
                var zoom   = map.getZoom();
                document.getElementById("XY").value = center;
                document.getElementById("zoom").value = zoom;
            }
        </script>
            
    </head>
    <body onload="init()">
        <span>鼠标点击坐标：</span>
        <input id="XY" type="text" value="0.0"></span>
        <!--地图的容器-->
        <div id="mapDiv"></div>
    </body>
</html>



